package cn.com.callback

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.com.elite.EliteBean;
import cn.com.elite.PropertiesUtil;
import cn.com.elite.Util;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import net.sf.json.JSONArray;

import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;

import java.net.URLEncoder;
import java.util.HashMap;
/**
安正接口集成
*/
public class Sms implements ServiceBackInvoke{
	private static final Log log=LogFactory.getLog(Sms.class);
	public String doCallBack(EliteBean eliteBean, HttpServletRequest request,HttpServletResponse response){
		try {
			def userid = "J22442";
			def pwd = "568787";
			def timestamp = Util.getNowString("MMddHHmmss");
			pwd = Util.getMD5Str(userid+"00000000"+pwd+timestamp);
			def mobile = "13246476522";
			def content = "同事您好，感谢您对此次测试的配合。123456";
			content = URLEncoder.encode(content,"utf-8");
			def svrtype = "SMS001";
			def exno = "0001";
			def custid = "SM201811050001";
			def exdata = "506044C6-247A-017A-8683-D6E220ADEA7F";
			JSONObject josnbody = new JSONObject();
			josnbody.put("userid",userid);
			josnbody.put("pwd",pwd);
			josnbody.put("mobile",mobile);
			josnbody.put("content",content);
			josnbody.put("timestamp",timestamp);
			josnbody.put("svrtype",svrtype);
			josnbody.put("exno",exno);
			josnbody.put("custid",custid);
			josnbody.put("exdata",exdata);
			log.debug("\n"+"josnbody:"+JSONObject.fromObject(josnbody).toString());
			Map headMap=new HashMap(); //设置头文件
			headMap.put("Content-Type","application/json");
			def charset = "utf-8"; //设置字符集
			def timeout = 100000; //设置请求超时时间
			def enableSSLflag = 0;
			def url = "http://172.16.5.134:7902/sms/v2/std/single_send";
			return Util.doHttpPostUseHead(url,JSONObject.fromObject(josnbody).toString(),charset,timeout,enableSSLflag,headMap);
			
		
			
			
			/** 对账单测试模块
			def map = eliteBean.chaxun_sql("select sk_invpty,product_cname from statement_productinfo","dataSource");
			JSONObject obj1 = new JSONObject();
			JSONObject obj2 = new JSONObject();
			JSONArray arr=new JSONArray();
			for(def i=0; i<map.size();i++) {
				obj2.put("c1",map[i].get("sk_invpty"));
				obj2.put("c2",map[i].get("product_cname"));
				arr.add(obj2);
			}
			obj1.put("tablea",arr);
			obj1.put("tableb",arr);
			def b=Util.getMergeContent(JSONObject.fromObject(obj1).toString(),"text.html","utf-8");
			log.debug("data:"+b);
			File file = new File("/app/kefu/elite.ngs/temp/text.txt");
			FileWriter fw = new FileWriter(file,true); //设置成true就是追加
			BufferedWriter bw=new BufferedWriter(fw);
			bw.write(b);
			bw.newLine();
			bw.close();
			fw.close();
			*/
		}catch(Exception e) {
			log.error("错误代码： ",e);
			return "{\"msg\": \"请求接口失败！\",\"code\": -1}"
		}
	}	
}